﻿using System;
using System.Security.Cryptography;
using System.Text;

namespace ServiceCore.Tool
{
    public class SecurityToMd5
    {
        public static string Start(string str)
        {
            //32位大写
            using (var md5 = MD5.Create())
            {
                var result = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
                var strResult = BitConverter.ToString(result);
                string result3 = strResult.Replace("-", "");
                return result3.ToLower();
            }
        }
        public static string Start(string str,bool Isother)
        {
            //32位大写 
            using (var md5 = MD5.Create())
            {
                var data = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
                StringBuilder builder = new StringBuilder();
                // 循环遍历哈希数据的每一个字节并格式化为十六进制字符串 
                for (int i = 0; i < data.Length; i++)
                {
                    builder.Append(data[i].ToString("X2"));
                }
                string result4 = builder.ToString();
                return result4.ToLower();
            }
        } 
        public static string Run(string source)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] bytes = Encoding.UTF8.GetBytes(source);
            string result = BitConverter.ToString(md5.ComputeHash(bytes));
            return result.Replace("-", "").ToLower();
        }
    }
}
